02. Displaying A Repository's Commits

TIP: In lesson 2 you used git clone to clone the blog project. This is the project we'll be using in this lesson. If you skipped cloning the project in the previous lesson, then run the following command to get the project:

$ git clone https://github.com/udacity/course-git-blog-project

Don't forget to cd into the project after you've cloned it.

If you have questions about this, review how to Clone An Existing Repo or ask in Knowledge.

First Things, First

After you’ve cloned the blog project repository, navigate to the project’s directory using the command line. Once you’re located inside the blog project, what is the very first thing you should do in a Git repository?

SOLUTION: run the `git status` command

_The Terminal application showing the output of the `git status` command._

The Terminal application showing the output of the git status command.

Git Status & Opening The Project

You can see that git status tells us that there's "nothing to commit, working directory clean". That means we're good to go ahead and check out the project!

So open the project in your favorite code editor. If you haven't yet, take a minute or two to look at the project – look over the CSS and the JavaScript files, but look particularly at the HTML file.

_The course's Blog project open in a code editor. The `index.html` file is being displayed._

The course's Blog project open in a code editor. The index.html file is being displayed.

When Was The Heading Added?

In the index.html file, take a look at the <h1>Expedition</h1> heading around line 15.

Based on what you can see here when was that heading added?

SOLUTION: ¯\\_(ツ)_/¯ I can't tell that by looking at the code.

Who Added The Heading?

Ok, so we're not quite sure when the heading was added. How about an easier question - who added this heading? Again, what can you tell from just looking at the code?

SOLUTION: No clue

The Git Log Command

Finding the answers to these questions is exactly what git log can do for us! Instead of explaining everything that it can do for us, let's experience it! Go ahead and run the git log command in the terminal:

$ git log

The terminal should display the following screen.

_The Terminal application showing the output of the `git log` command._

The Terminal application showing the output of the git log command.

Nd016 WebND Ud123 Gitcourse BETAMOJITO L3 11 Git Log Output Explained

If you're not used to a pager on the command line, navigating in Less can be a bit odd. Here are some helpful keys:

  • to scroll down, press
    • j or to move down one line at a time
    • d to move by half the page screen
    • f to move by a whole page screen
  • to scroll up, press
    • k or to move up one line at a time
    • u to move by half the page screen
    • b to move by a whole page screen
  • press q to quit out of the log (returns to the regular command prompt)

Git records a ton of information when a commit is made. See if you can use git log to answer the following questions!

Who Made The Commit?

Use git log to find the commit that has a SHA that starts with f9720a. Who made the commit?

SOLUTION: Richard Kalehoff

What Is The Message?

QUESTION:

Use git log to find the commit with the SHA that starts with 8aa6668. What is the message for that commit?

SOLUTION:

NOTE: The solutions are expressed in RegEx pattern. Udacity uses these patterns to check the given answer

When Was The Commit Made?

Use git log to find the commit with the SHA that starts with f9720a9. When was that commit made?

SOLUTION: Mon Dec 5 10:11:51 2016

What Is The SHA?

QUESTION:

Use git log to find the commit that has the message Set article timestamp color. Which commit belongs to that SHA? Provide the first 7 characters of the SHA.

SOLUTION:

NOTE: The solutions are expressed in RegEx pattern. Udacity uses these patterns to check the given answer

Git Log Recap

Fantastic job! Do you feel your Git-power growing?

Let's do a quick recap of the git log command. The git log command is used to display all of the commits of a repository.

$ git log

By default, this command displays:

  • the SHA
  • the author
  • the date
  • and the message

…of every commit in the repository. I stress the "By default" part of what Git displays because the git log command can display a lot more information than just this.

Git uses the command line pager, Less, to page through all of the information. The important keys for Less are:

  • to scroll down by a line, use j or
  • to scroll up by a line, use k or
  • to scroll down by a page, use the spacebar or the Page Down button
  • to scroll up by a page, use b or the Page Up button
  • to quit, use q

We'll increase our git log-wielding abilities in the next lesson when we look at displaying more info.

Why wait?!? Click the link to move to the next lesson!